<?php
/**
* Accounts
* Manage registered users of the system
* 
* @package Account
* @author Argem Gerald R. Flores <argemgrflores@gmail.com>
* @version 1.0
*/
class Account {
	/**
	* @var mixed Mysql connection
	*/
	var $mysqli = null;
	/**
	* @var array User credentials (id, email, type)
	*/
	var $user = null;
	/**
	* @var array Notifications
	*/
	var $notif = array();
	
	/**
	* Account constructor
	* Initializes Account variables for intended request
	* 
	* @param resource $mysqli current mysql connection
	* @param resource $user user credentials (id, email, type)
	*/
	function __construct($mysqli, $user) {
		# require class Tool for extra functions
		require_once "class/tool.php";
		
		# assign mysql resource and user credentials
		$this->mysqli = $mysqli;
		$this->user = $user;
	} # function __construct
	
	/**
	* Search account
	* Searches for an account based on
	* query string, optional paramaters as constraints,
	* start and end line of result in a mysql resource
	* 
	* @access public
	* @param string $query Keyword/s to look for in the database
	* @param array $opts Contains constraints in search (category, order, author, etc.)
	* @param integer $start Beginning line of searched keyword in mysql resource
	* @param integer $limit End of returned mysql resource as a result of search
	* 
	* @return array Mixed result from mysql query and size of returned rows
	*/
	public function search($query, $opts, $start, $limit) {
		# Replaces all comma's to make valid query string
		$query = is_array($query) ? $query : str_replace(',', ' ', $query);
		# If edtr is specified, set table to Editors; else, default to Accounts
		$table = empty($opts['edtr']) ? "Accounts" : "Editors";
		# Selects size of returned rows in mysql search
		$selSize = "SELECT FOUND_ROWS()";
		
		# Set order according to name or something else
		$opts['ob'] = isset($opts['ob']) ? $opts['ob'] : 'Lname, Fname';
		# According to ascending or descending order
		$opts['oa'] = isset($opts['oa']) ? $opts['oa'] : 'ASC';
		
		# Search for an Account ID
		if(!empty($opts['c'])) {
			if($opts["c"]=="id") {
				$sel = "SELECT SQL_CALC_FOUND_ROWS * FROM Accounts WHERE ID='{$query}' ".(empty($opts['id']) ? '' : "OR ID='{$opts['id']}'");
			}
			elseif($opts['c']=="multi-id") {
				$sel = "SELECT SQL_CALC_FOUND_ROWS * FROM Accounts WHERE ID IN ('".implode("','", $query)."') ORDER BY {$opts['ob']} {$opts['oa']}";
			}
			elseif($opts['c']=="remove") {
				$sel = "SELECT SQL_CALC_FOUND_ROWS * FROM Accounts WHERE Remove='1' ORDER BY {$opts['ob']} {$opts['oa']}";
			}
		}
		else {
			# Part query from string into an array based on spaces contained
			$arrQuery = is_array($query) ? explode(" ", $query) : array($query);
			
			# Set conditional query if any condition is needed
			$cond = " WHERE ";
			# Set query string on Email, Lname, and Fname
			foreach($arrQuery as $query) {
				$query = Tool::trimout($query);
				$cond .= " (ID='{$query}' OR Email LIKE '%{$query}%' OR ";
				$cond .= " Lname LIKE '%{$query}%' OR ";
				$cond .= " Fname LIKE '%{$query}%' OR ";
				$cond .= " Mname LIKE '%{$query}%') AND ";
			}
			
			# Remove final OR in query string
			# Start and End of row search
			$start = isset($start) ? $start : '0';
			$limit = isset($limit) ? $limit : '10';
			
			# Removed items
			$cond .= (in_array($this->user['type'], array('ADMIN','PRIME')) and $opts['c']=='remove') ? " Remove='1' " : " Remove='0' ";
			
			# Query string, combined with conditions and order parameters
			$sel = "SELECT SQL_CALC_FOUND_ROWS * FROM {$table} {$cond} ORDER BY {$opts['ob']} {$opts['oa']} LIMIT {$start}, {$limit}";
		}
		
		# Perform a mysql query on passed query string
		$res = $this->mysqli->query($sel);
		# Get size of rows in mysql returned resource
		$size = $this->mysqli->query($selSize);
		$size = $size->fetch_row();
		
		# Return all returned and size of rows
		return array($res, $size[0]);
	} # function search
	
	/**
	* Create account
	* Create a new system account
	* (type, email, password, lastname, firstname, middlename, address)
	* 
	* @access public
	* @param string $type Prime (highest), Admin, or Editor each with respective privileges
	* @param string $email Email of new account
	* @param string $pword Password of new account
	* @param string $lname Lastname of new account
	* @param string $fname Firstname of new account
	* @param string $mname Middlename of new account
	* @param string $addrs Address of new account
	* 
	* @return array mixed result from mysql query and size of returned rows
	*/
	public function create($type, $email, $pword, $lname, $fname, $mname, $addrs) {
		# Generate an account id
		$ida = Tool::generateID('acct');
		
		# Generate an editor id (every account has an editor entry)
		$ide = Tool::generateID('edtr');
		
		# Encrypt password if it is less than 100 characters, else retain
		$pword = strlen($pword) < 100 ? $this->hashsalt($pword) : $pword;
		
		# Prepare values for mysql string query
		$type = Tool::mysqlEscStr($type);
		$email = Tool::mysqlEscStr($email);
		$pword = Tool::mysqlEscStr($pword);
		$lname = Tool::mysqlEscStr($lname);
		$fname = Tool::mysqlEscStr($fname);
		$mname = Tool::mysqlEscStr($mname);
		$addrs = Tool::mysqlEscStr($addrs);
		$userid = $this->user['id'];
		$date = date('Y-m-d H:i:s:ms');
		
		# Check editor entry
		echo $sel = "SELECT * FROM Editors WHERE Author='1' AND ((Lname='$lname' AND Fname='$fname' AND Mname='$mname') OR Email='$email')";
		$res = $this->mysqli->query($sel);
		
		if(empty($res->num_rows)) {
			# Prepare string for inserting editor
			$inse = "INSERT INTO Editors VALUES (
				'$ide', '$email', '0', '1', '$lname', '$fname', '$mname', NULL, NULL, '0', '$userid', '$date', '0'
			)";
			# Perform insertion of editor
			$fedtr = $this->mysqli->query($inse);
		}
		else {
			# Update editor if existing
			$edtr = $res->fetch_object();
			echo $upd = "UPDATE Editors SET Editor='1', Email='$email' WHERE ID='{$edtr->ID}'";
			if(!$this->mysqli->query($upd)) {
				$this->notif[] = "ERROR: upd edtr<br/>";
			}
			$ide = $edtr->ID;
			$fedtr = true;
		}
		
		# Prepare string for inserting account
		echo $insa = "INSERT INTO Accounts VALUES (
			'$ida', '$ide', '$type', '$email', '$pword', '$lname', '$fname', '$mname', '$addrs',
			NULL, NULL, NULL, NULL, 0, '$userid', '$date', '0'
		)";
		# Perform insertion of account
		$facct = $this->mysqli->query($insa);
		
		# Both queries passed, return account id
		if($facct and $fedtr) {
			return $ida;
		}
		
		# Unsuccesful in either account or editor creation, return false
		return false;
	} # function create
	
	/**
	* Update account
	* Update an existing system account
	* (id, type, report, email, password, lastname, firstname, middlename, address)
	* 
	* @access public
	* @param string $id Account ID
	* @param string $type Prime (highest), Admin, or Editor each with respective privileges
	* @param string $report Any additional information on the user
	* @param string $email Email of account
	* @param string $pword Password of account
	* @param string $lname Lastname of account
	* @param string $fname Firstname of account
	* @param string $mname Middlename of account
	* @param string $addrs Address of account
	* 
	* @return array mixed result from mysql query and size of returned rows
	*/
	public function update($id, $type, $report, $email, $pword, $lname, $fname, $mname, $addrs) {
		$type = Tool::mysqlEscStr($type);
		$report = Tool::mysqlEscStr($report);
		$email = Tool::mysqlEscStr($email);
		$pword = empty($pword) ? "" : "Pword='{$this->hashsalt($pword)}', ";
		$lname = Tool::mysqlEscStr($lname);
		$fname = Tool::mysqlEscStr($fname);
		$mname = Tool::mysqlEscStr($mname);
		$addrs = Tool::mysqlEscStr($addrs);
		$userid = $this->user['id'];
		$date = date('Y-m-d H:i:s:ms');
		$id = Tool::mysqlEscStr($id);
		
		# Prepare update string
		$upd = "
			UPDATE Accounts SET
				Type='$type', Report='$report', Email='$email', $pword
				Lname='$lname', Fname='$fname', Mname='$mname', Addrs='$addrs',
				UpdBy='$userid', UpdOn='$date'
			WHERE ID='$id'
		";
		
		# Perform update in mysql
		$result = $this->mysqli->query($upd);
		
		# Unsuccessful, return false
		if(!$result) {
			return false;
		}
		
		# Successful, return true
		return true;
	} # function update
	
	/**
	* Delete account
	* Delete an existing account from the system
	* 
	* @access public
	* @param string $id Account ID
	* 
	* @return boolean true on successful deletion, false on failure
	*/
	public function delete($id) {
		# Escape route; refuse if acccount to be deleted is currently logged in
		if($this->user['id'] == $id) {
			return false;
		}
		
		# Select associated editor id of account to be deleted
		$sel = "SELECT * FROM Accounts WHERE ID='{$id}'";
		
		# Perform mysql selection of editor
		$res = $this->mysqli->query($sel);
		# Get associated editor object
		$acct = $res->fetch_object();
		
		# Editor account is non-existent, return false
		if(!$res or empty($res->num_rows)) {
			return false;
		}
		
		# Prepare string to delete account
		$del = "UPDATE Accounts SET Remove='1' WHERE ID='{$id}'";
		
		# Perform delete account on mysql
		$res = $this->mysqli->query($del);
		
		# On deletion error, return false
		if(!$res) {
			return false;
		}
		
		# Prepare string to delete editor
		$del = "UPDATE Editors SET Remove='1' WHERE ID='{$acct->EID}'";
		
		# Perform delete editor on mysql
		$res = $this->mysqli->query($del);
		
		# Error occurred, return false
		if(!$res) {
			return false;
		}
		
		# Deleted successfully
		return true;
	} # function delete
	
	/**
	* Recover account
	* Recover a deleted account
	* 
	* @access public
	* @param string $id Account ID
	* 
	* @return boolean true on success, false on failure
	*/
	public function recover($id) {
		# Query string to recover account
		$del = "UPDATE Accounts SET Remove='0' WHERE ID='{$id}'";
		
		# Recover account in the database
		$res = $this->mysqli->query($del);
		
		# Error occurred in deletion
		if(!$res) {
			echo "ERROR: recover";
			return false;
		}
		
		# Successfully recovered account
		return true;
	} # function recover
	
	/**
	* Verify account
	* Check if an account is registered in the system
	* given the email and password of the account
	* 
	* @access public
	* @param string $email Email of account
	* @param string $pword Password of account (encrypted)
	* 
	* @return object|false Object if successfully verified, false if not
	*/
	public function verify($email, $pword) {
		# Instantiate an Account for search request
		$acct = new Account($this->mysqli, $this->user);
		
		# Search email from Accounts
		$res = $acct->search($email, null, 0, 1);
		
		# Email is not found, return false
		if(!$res[0] or empty($res[1])) {
			return false;
		}
		
		# Get account from the results (first item in array is the mysql rows)
		$acct = $res[0]->fetch_object();
		
		# Input password is not correct; email-password combination error
		if($acct->Pword != $this->hashsalt($pword)) {
			return false;
		}
		
		# Email is found and password is correct
		return $acct;
	} # function verify
	
	/**
	* Display all accounts
	* Retrieve all contents of accounts on a page
	* 
	* @access public
	* @param array $queries IDs of accounts
	*/
	public function displayAll($queries, $opts) { ?>
		<output> <?php
			if($results = $this->search($queries, $opts, 0, 10)) {
				while($result = $results[0]->fetch_object()) {
					$this->displayContent($result, false);
				}
			} ?>
		</output> <?php
	}
	
	/**
	* Guess account
	* Provides a list of accounts (guess) on user input
	* Makes selection of account and id faster
	* 
	* @access public
	* @param string $query Account's name or email to be searched for
	* 
	* @return mixed|false Mixed if query is found, false if not
	*/
	public function guess($query) {
		# Search for user accounts matching the query string and constrains passed
		$accts = $this->search($query, $_REQUEST, 0, 10);
		
		# Account is not found
		if(!$accts or empty($accts[1])) {
			return false;
		}
		
		# List all accounts in the search results
		while($acct = $accts[0]->fetch_object()) { ?>
			<div class="guess acct" data-id="<?php echo $acct->ID ?>" data-eid="<?php echo empty($acct->EID) ? $acct->ID : $acct->EID ?>"
				data-value="<?php echo $acct->Lname.", ".$acct->Fname.", ".$acct->Mname ?>" tabindex="0"> <?php
				echo $acct->Lname.", ".$acct->Fname.", ".substr($acct->Mname, 0, 1)."." ?>
			</div> <?php
		}
		
		if($_REQUEST['s']=='true') { ?>
			<div class="guess-header acct query">
				<a href="main.php?acct=view&q=<?php echo urlencode($query) ?>" target="_blank" title="<?php echo $query ?>"><?php echo Tool::truncate($query, 30) ?></a>
				<span class="right bold none" title="<?php echo ($found = $accts[0]->num_rows.' of '.$accts[1]).' items found' ?>"><?php echo $found ?></span>
			</div> <?php
		}
	} # function guess
	
	/**
	* Hash password
	* Encrypt user password using sha512 hash algorithm
	* 
	* @access public
	* @param string $pword Password of an account to be created or verified
	* 
	* @return string Encrypted string of the password
	*/
	public function hashsalt($pword) {
		return hash('sha512', $pword);
	} # function hashsalt
	
	/**
	* Display main account stage
	* List all accounts in the main page
	* 
	* @access public
	* @param mixed $accts List of accounts from returned search results
	* @param integer $size Size of rows from returned search results
	* @param string $query Query string that was searched for
	* @param array $opts Optional parameters
	* @param integer $start Starting row in mysql returned mixed results
	*/
	public function displayMain($accts, $size, $query, $opts, $start) {
		# Check if one account is to be displayed
		$view = $accts->num_rows==1;
		# Get page number
		$page = ceil(($start+1)/10);
		# Prepare GET variables
		$optstr = Tool::optstrify($opts); ?>
		
		<div id="side"> <?php
			# Show Back and Next buttons for navigation ?>
			<div id="navis"> <?php
				# Links to previous ten items ?>
				<a href="main.php?<?php echo $optstr.(empty($query) ? '' : '&q='.$query).(empty($start) ? '&s=0' : '&s='.(intval($start)-10)) ?>"
					class="navi ui ui-button prev <?php if(empty($start)) echo 'disabled' ?>" tabindex="-1" title="Previous 10 items"></a> <?php
				# Links to next ten items ?>
				<a href="main.php?<?php echo $optstr.(empty($start) ? '&s=10' : '&s='.(intval($start)+10)) ?>"
					class="navi ui ui-button next <?php if(($accts->num_rows<10) or ($accts->num_rows*$page)>=$size) { echo 'disabled'; } ?>" tabindex="-1" title="Next 10 items"></a>
			</div> <?php
			
			# Knobs to stage an account ?>
			<div id="knobs"> <?php $i = 1;
				while($acct = $accts->fetch_object()) {
					# Contains data query (Email), id (Account ID), tool (tooltip help)
					$name = Tool::truncate($trname = "{$acct->Lname}, {$acct->Fname}, ".substr($acct->Mname, 0, 1).'.', 80); ?>
					<div class="knob acct <?php if($view) echo "lock" ?>" data-query="<?php echo $acct->Email ?>"
						data-id="<?php echo $acct->ID ?>" data-tool="{'head':'<b class=\'cool\'><?php echo $name ?></b>','x':'l'}"> <?php
						echo $i++ ?>
					</div> <?php
				} ?>
			</div>
		</div> <?php
		
		# Labels stage items (header) ?>
		<div id="hnotif" class="escape"> <?php
			# Shows metadata of all searched items ?>
			<span id="query" class="escape iblock" data-tool="{'head':'<?php echo ($all = empty($query)) ? "All accounts" : $trname ?>','x':'l'}"
				<?php if(!($nctrl = empty($_COOKIE['ctrl']['search']))) { echo 'style="width:400px"'; } ?>>
				<?php echo ($all ? "All accounts" : ($view ? $name : $query)) ?>
			</span>
			
			<span>
				<span id="search-ctrls" <?php if($nctrl) { echo 'class="none"'; } ?>> <?php
					# No. of returned results
					echo '<span id="numresults">Showing '.($accts->num_rows).' of <b>'.$size.'</b> result(s)</span> on page ';
					
					# Many microorganisms are to be viewed
					$ob = isset($_REQUEST['ob']); $of = true;
					unset($opts['ob']); unset($opts['oa']);
					$optstr = Tool::optstrify($opts);
					
					# Prepare filter options and page selector ?>
					<select id="main-page" class="page navi" data-tool="{'head':'Page'}"> <?php
						for($i=0, $x=$size/10; $i<$x; $i++)	echo "<option ".((isset($opts['s']) and $opts['s']==($i*10)) ? 'selected="selected"' : '').'value="main.php?'.$optstr.(empty($query) ? '' : '&q='.$query).'&s='.($i*10).'">'.($i+1).'</option>';?>
					</select> sorted by <?php
					
					# Prepare filter options ?>
					<select class="navi" data-tool="{'head':'Page'}">
						<option value="main.php?<?php echo $optstr ?>&ob=lname&oa=asc" <?php if($ob and $_REQUEST['ob']=='lname') { echo 'selected="selected"'; $of = false; } ?>>Name</option>
						<option value="main.php?<?php echo $optstr ?>&ob=email&oa=asc" <?php if($ob and $_REQUEST['ob']=='email') { echo 'selected="selected"'; $of = false; } ?>>Email</option>
						<option value="main.php?<?php echo $optstr ?>&ob=type&oa=asc" <?php if($ob and $_REQUEST['ob']=='type') { echo 'selected="selected"'; $of = false; } ?>>Type</option>
						<option value="main.php?<?php echo $optstr ?>&ob=sgnon&oa=desc" <?php if($ob and $_REQUEST['ob']=='sgnon') { echo 'selected="selected"'; $of = false; } ?>>Last signon</option>
						<option value="main.php?<?php echo $optstr ?>&ob=crtby&oa=asc" <?php if($ob and $_REQUEST['ob']=='crtby') { echo 'selected="selected"'; $of = false; } ?>>Author</option>
						<option value="main.php?<?php echo $optstr ?>&ob=updon&oa=desc" <?php if($ob and $_REQUEST['ob']=='updon') { echo 'selected="selected"'; $of = false; } ?>>Last edited</option>
						<option value="main.php?<?php echo $optstr ?>&ob=crton&oa=desc" <?php if($ob and $_REQUEST['ob']=='crton') { echo 'selected="selected"'; $of = false; } ?>>Date created</option>
						<option value="main.php?<?php echo $optstr ?>&ob=id&oa=asc" <?php if($ob and $_REQUEST['ob']=='id') { echo 'selected="selected"'; $of = false; } ?>>ID</option>
					</select>
				</span>
				<span <?php if(!$nctrl) { echo 'class="none"'; } ?>><?php echo "$accts->num_rows of <b>$size</b> result(s) on page <b>$page</b>";  ?></span> <button type="button" class="navi-details <?php echo (!$nctrl ? 'selected' : '') ?>" data-tool="{'head':'Search controls'}"></button>
			</span>
		</div> <?php
		
		# Contains all account headers ?>
		<div id="stage"> <?php
			# Reset pointer to first row in mysql result
			$accts->data_seek(0);
			
			# List all accounts on its own entry page
			while($acct = $accts->fetch_object()) {
				# Show first the heading of each account
				$this->displayHeading($acct, $view);
			} ?>
		</div> <?php
	} # function displayMain
	
	/**
	* Display an account heading
	* Displays a heading for each account in the results
	* which contains the account's full name and email
	* 
	* @access public
	* @param mixed $acct Contains all details of the account
	* @param boolean $cont Checks if content is to be displayed too
	*/
	public function displayHeading($acct, $cont) {
		# List an account first as an area with a header that can be selected/clicked by the user in the stage
		# Data included: head (name of the account), id (account id)
		?> <div id="area<?php echo $acct->ID ?>" data-id="<?php echo $acct->ID ?>" class="stage area acct"
			data-head="<?php echo $name = "{$acct->Lname}, {$acct->Fname} ".substr($acct->Mname, 0, 1).'.' ?>">
			<div class="div-header acct <?php echo $cont ? "active lock" : "heading" ?>" data-id="<?php echo $acct->ID ?>" data-content="acct">
				<a href="main.php?acct=view&id=<?php echo $acct->ID ?>" class="name" tabindex="-1"><?php echo $name ?></a>
				<span class="email right"><?php echo $acct->Email ?></span>
			</div> <?php
			
			# Show account's contents if true
			if($cont) {
				$this->displayContent($acct, $cont);
			} ?>
		</div> <?php
	} # function displayHeading
	
	/**
	* Display account contents
	* Displays the contents of an account, from its name to its address
	* 
	* @access public
	* @param mixed $acct Contains all details of the account
	* @param boolean $cont Checks if only one account is found in results
	*/
	public function displayContent($acct, $cont) {
		$id = $acct->ID;
		
		?> <div class="div-content">
			<form id="form-acct<?php echo $id ?>" data-id="<?php echo $id ?>" name="form-acct[]" class="acct" novalidate="novalidate">
			<div class="div-upper">
				<div class="div-head">
					<label>Type:</label> <?php
					# Set the account's type as default in the selection ?>
					<select name="type" class="reqd <?php if($acct->Type=='PRIME' and $acct->ID==$this->user['id']) { echo 'readonly'; } ?>">
						<option value="PRIME" <?php if($acct->Type=='PRIME') echo "selected=\"selected\"" ?>>Prime</option>
						<option value="ADMIN" <?php if($acct->Type=='ADMIN') echo "selected=\"selected\"" ?>>Admin</option>
						<option value="EDITOR" <?php if($acct->Type=='EDITOR') echo "selected=\"selected\"" ?>>Editor</option>
						<option value="CLIENT" <?php if($acct->Type=='CLIENT') echo "selected=\"selected\"" ?>>Client</option>
					</select><br/> <?php
					
					# Shows the account's current report as an input ?>
					<label>Report:</label> <input name="report" type="text" value="<?php echo $acct->Report ?>" class="abled"/><br/> <?php
					
					# Shows the account's email as an input ?>
					<label>Email:</label> <input name="email" type="email" value="<?php echo $acct->Email ?>" class="reqd"/><br/> <?php
					
					# Shows inputs for changing password ?>
					<label>Password:</label>
					<span class="spnPwordNew none">
						<input name="pwordNew" type="password" placeholder="New password" class="tipped"/><br/>
						<input name="pwdPwordNewRep" type="password" placeholder="Repeat new password"/><br/>
					</span>
					<a class="lnkChangePword peel on prev" tabindex="0">Change current password</a>
					<input name="cbxUpdPword" type="checkbox" value="<?php echo $id ?>" class="none"/>
				</div> <?php
				
				# Contains name and address of account ?>
				<div class="div-body">
					<label>Last name:</label> <input name="lname" type="text" value="<?php echo $acct->Lname ?>" class="reqd"/><br/>
					<label>First name:</label> <input name="fname" type="text" value="<?php echo $acct->Fname ?>" class="reqd"/><br/>
					<label>Middle name:</label> <input name="mname" type="text" value="<?php echo $acct->Mname ?>" class="reqd"/><br/>
					<label>Address:</label> <input name="addrs" type="text" value="<?php echo $acct->Addrs ?>" class="reqd"/><br/>
					
					<input name="id" type="hidden" value="<?php echo $id ?>"/>
					<input name="name" type="hidden" value="<?php echo $acct->Lname.', '.$acct->Fname.' '.substr($acct->Mname, 0, 1).'.' ?>"/>
					<input name="del" type="checkbox" value="<?php echo $id ?>" class="abled none"/>
					<input name="recov" type="checkbox" value="<?php echo $id ?>" class="abled none"/>
				</div>
			</div>
			
			<div class="div-dial">
				<span class="left"> <?php
					# Set delete button if the current user is not this account or a prime user is logged in
					if($this->user['id']!=$acct->ID) {
						if($acct->Remove=='0') { ?>
							<button class="delete tick acct" type="button" form="form-acct<?php echo $acct->ID ?>" data-area="acct">Delete</button> <?php
						}
						else { ?>
							<button class="recover tick acct" type="button" form="form-acct<?php echo $acct->ID ?>" data-area="acct">Recover</button> <?php
						}
					} ?>
					<button type="reset" form="form-acct<?php echo $id ?>" class="reset">Reset</button>
					<a style="margin-left:10px" href="main.php?edtr=view&id=<?php echo $acct->EID ?>" title="Account's editor page" target="_blank">Editor</a>
				</span> <?php
				
				# Show close if not solo account
				if(!$cont) { ?>
					<button type="button" class="close-content reset">Close</button> <?php
				} ?>
				
				<button type="submit">Update</button>
			</div>
			</form>
		</div> <?php
	} # function displayContent
}
?>
